
#ifndef __LIBERTY_ENGINE_CACHECLEANER_H__
#define __LIBERTY_ENGINE_CACHECLEANER_H__

#include <unordered_map>

namespace Liberty { namespace Engine {
	template <
		typename Key,
		typename T,
		typename Hash,
		typename Pred,
		typename Alloc>
	void EraseExpired(std::unordered_map<Key, T, Hash, Pred, Alloc>& map) {
		typedef typename std::unordered_map<Key, T, Hash, Pred, Alloc>           Map;
		typedef typename std::unordered_map<Key, T, Hash, Pred, Alloc>::iterator MapIterator;

		MapIterator it, end(map.end());

		for (it = map.begin(); it != end;) {
			if ((*it).second.expired()) {
				it = map.erase(it);
			}
			else {
				++it;
			}
		}
	};
}}

#endif
